/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.client.veditor.view.hyperlink;

import java.net.MalformedURLException;
import java.net.URL;
import offset.nodes.client.model.NodeTypes;
import offset.nodes.client.editor.Editor;
import offset.nodes.client.veditor.VirtualEditor;
import offset.nodes.client.editor.view.hyperlink.DataHyperlinkInfo;
import offset.nodes.client.editor.view.hyperlink.HyperlinkDialog;

/**
 *
 * @author  Walter Lütgenau
 */
public class VirtualHyperlinkDialog extends HyperlinkDialog {

    public static final int TYPE_DATA = 2;
    
    private DataHyperlinkPanel dataHyperlinkPanel;

    /** 
     * Creates a new HyperlinkDialog
     * 
     * @param editor A reference to the editor
     */
    public VirtualHyperlinkDialog(Editor editor) throws Exception {
        super(editor);
     }

    public DataHyperlinkInfo getDataHyperlinkInfo() {
        if (getTabbedPane().getSelectedIndex() != TYPE_DATA)
            return null; // not yet implemented
        return dataHyperlinkPanel.getResult();
    }

    protected void initDataHyperlinkPanel() throws Exception {
        getTabbedPane().setEnabledAt(TYPE_DATA, true);

        try {
            dataHyperlinkPanel.init(getEditor(), (NodeTypes) getEditor().getProperties().get(Editor.PROP_NODE_TYPES),
                    this, new URL((String) getEditor().getProperties().get(Editor.PROP_UPLOAD_TO)));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public void init(int mode) throws Exception {
        dataHyperlinkPanel = new DataHyperlinkPanel();
        getTabbedPane().addTab(java.util.ResourceBundle.getBundle("offset/nodes/client/veditor/view/resources/EditorBundle").getString("Hyperlink.data"), dataHyperlinkPanel); // TODO: move bundle entries   
 
        getTabbedPane().setEnabledAt(TYPE_INTERNAL, false);
        getTabbedPane().setEnabledAt(TYPE_DATA, false);
        getTabbedPane().setEnabledAt(TYPE_EXTERNAL, false);

        switch (mode) {
            case Editor.MODE_LOCAL_PAGE_EDITOR:
            case Editor.MODE_PAGE_EDITOR:
                initInternalHyperlinkPanel();
                initExternalHyperlinkPanel();
                getTabbedPane().setSelectedIndex(TYPE_INTERNAL);
                break;

            case VirtualEditor.MODE_TEMPLATE_EDITOR:
            case VirtualEditor.MODE_VIRTUAL_PAGE_EDITOR:
                initInternalHyperlinkPanel();
                initExternalHyperlinkPanel();
                initDataHyperlinkPanel();
                getTabbedPane().setSelectedIndex(TYPE_DATA);
                break;

            case VirtualEditor.MODE_VIRTUAL_PAGE_DATA_EDITOR:
                break;
        }
    }

    public DataHyperlinkPanel getDataHyperlinkPanel() {
        return dataHyperlinkPanel;
    }
}
